package com.graduate.after.web.control;

import com.graduate.after.bean.HomeCategory;
import com.graduate.after.bean.SlideShow;
import com.graduate.after.constants.StatusCode;
import com.graduate.after.exception.GraduateException;
import com.graduate.after.service.HomeCategoryService;
import com.graduate.after.service.SlideShowService;
import com.graduate.after.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.ws.rs.Path;
import java.util.*;

@Controller
@ResponseBody
@RequestMapping("/home")
public class HomeControl {

    @Autowired
    private SlideShowService slideShowService;

    @Autowired
    private HomeCategoryService homeCategoryService;

    @RequestMapping("/slideShow")
    public Result homeSlideShow() {
        Map map = new HashMap();
        List<SlideShow> slideShows = slideShowService.homeSlideShowSelect();
        map.put("banners",slideShows);
        return Result.success(map);
    }

    @RequestMapping("/category")
    public Result homeCategory(Integer category, Integer page) {
        if(category == null || page == null) {
            throw new GraduateException(StatusCode.PARAM_IS_BLANK);
        }
        List<HomeCategory> homeCategories = homeCategoryService.homeCategorySelect(category, page);
        Iterator<HomeCategory> iterator = homeCategories.iterator();
        return Result.success(homeCategories);
    }

}
